package com.rayboo.example.design.pattern.chain;

public abstract class Leader {

    private Leader mNextHandler;

    public Leader(Leader nextHandler) {
        mNextHandler = nextHandler;
    }

    public final boolean dispatchRequest(int money) {
        if (money <= getLimit()) {
            return handleRequest(money);
        }
        if (mNextHandler != null) {
            return mNextHandler.dispatchRequest(money);
        }
        return false;
    }

    public abstract int getLimit();
    public abstract boolean handleRequest(int money);
}
